﻿using System;
using System.Web.Security;
using System.Web.UI;
using Meotom.Upload.v2.Data;
using Meotom.Upload.v2.Data.BLL;

namespace Meotom.Upload.v2.Account
{
    public partial class SendPassword : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var userId = Request.QueryString["uId"];
                if (userId == null) return;

                var user = Membership.GetUser(new Guid(userId));
                if (user == null) return;

                var isLostPass = WProfile.GetProfile(user.UserName).UserInfo.IsLostPass;
                if (!isLostPass) return;

                var strPasswordTemp = user.ResetPassword();
                using (var sReader = new System.IO.StreamReader(Configs.FolderSaveData + @"\template\LostPassword_Step2.htm"))
                {
                    var strTemp = sReader.ReadToEnd();
                    strTemp = strTemp.Replace("{0}", user.UserName);
                    strTemp = strTemp.Replace("{1}", strPasswordTemp);

                    var mailer = new mailer.MeoTom_Services();
                    mailer.SendMail(user.Email, "[Up.Meotom.Net] - Quen mat khau - Buoc 2", strTemp, "");
                }

                var profile = WProfile.GetProfile(user.UserName);
                profile.UserInfo.IsLostPass = false;
                profile.Save();
            }
            catch (Exception)
            {
            }
        }
    }
}